package com.topsun.framework.common.core.enums;

import cn.hutool.core.collection.CollUtil;

import java.util.Set;

/**
 * @Package jiangdu.fire.enums
 * @author: 皮皮
 * @date: 2020/12/20 9:40 PM
 */
public enum ContentTypeEnum {

    /**
     * 常用的文件ContentType
     */
    APPLICATION_OCTET_STREAM("application/octet-stream", "", "二进制文件"),
    APPLICATION_PDF("application/pdf", "pdf", "pdf文件"),

    TEXT_HTML("text/html", "html", "HTML格式"),
    TEXT_PLAIN("text/plain", "txt", "纯文本格式"),
    TEXT_XML("text/xml", "xml", "XML格式"),


    IMAGE("image/*", "jpg", "默认jpg"),
    IMAGE_GIF("image/gif", "gif", "gif图片"),
    IMAGE_JEPG("image/jpeg", "jpeg", "jpg图片"),
    IMAGE_PNG("image/png", "png", "png图片"),

    VIDEO("video/*", "mp4", "mp4"),
    VIDEO_MPEG4("video/mpeg4", "mp4", "mp4"),
    VIDEO_MP4("video/mp4", "mp4", "mp4"),
    VIDEO_QUICKTIME("video/quicktime", "mov", "mov"),
    VIDEO_AVI("video/avi", "avi", "avi"),


    AUDIO("audio/*", "mp3", "默认mp3"),
    AUDIO_MPEG("audio/mpeg", "mp3", "mp3音频"),
    AUDIO_WAV("audio/wav", "wav", "wav音频"),
    ;

    private final String type;

    private final String fileSuffix;

    private final String desc;

    public String getType() {
        return type;
    }

    public String getDesc() {
        return desc;
    }

    public String getFileSuffix() {
        return fileSuffix;
    }

    ContentTypeEnum(String type, String fileSuffix, String desc) {
        this.type = type;
        this.fileSuffix = fileSuffix;
        this.desc = desc;
    }

    public static Set<String> videos = CollUtil.newHashSet(VIDEO.getType(), VIDEO_MP4.getType(), VIDEO_QUICKTIME.getType(), VIDEO_MPEG4.getType(), VIDEO_AVI.getType());

    public static String getFileSuffixByType(String type) {
        for (ContentTypeEnum value : ContentTypeEnum.values()) {
            if (value.getType().equals(type)) {
                return value.getFileSuffix();
            }
        }
        return null;
    }
}
